home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Utilities.h
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __UTILITIES__
- #define __UTILITIES__
-
- #ifndef __IOSTREAM__
- #include "iostream.h"
- #endif
-
- #ifndef __OCE__
- // #include "OCE.h"
- #endif
-
- struct RString;
-
- const short kFolder = 0;
- const short kFile = 1;
- const short kNotFileOrFolder = -1;
-
- //
- // FILE RELATED FUNCTIONS
- // ======================
- //
-
- // GetIndexHFSInfo: For a given vRefNum, dirRefNum and index, return the refNum, filename and
- // whether kFolder,kFile, or kNotFileOrFolder. If the index = 0 then return
- // the information for file in the directory with theName
- OSErr GetIndexHFSInfo(short index, short vRefNum, long dirRefNum, const StringPtr theName);
- OSErr GetIndexHFSInfo(short index, short vRefNum, long dirRefNum, long& refNum, const StringPtr theName, short& isFile);
-
-
- // CreatFolderIfItDoesntExist: Given a folder name and its parent folder's dirID create a folder
- // if it doesn't exist. Return the dirID of the folder.
- long CreateFolderIfItDoesntExist(short vRefNum, long parentDir, const StringPtr folderName);
-
-
- // Given a folder id this call deletes all the visible files in a folder
- void DeleteFilesInFolder(short vRefNum, long folderID);
- void DeleteFilesInFolderOlderThan ( short vRefNum, long dirID, unsigned long deleteFilesBeforeDateTime);
-
-
- // GetDirIDForFolder: Return the dirID for a folder, given the vRefNum of the disk and the folder
- // name. If the folder does not exist, return 0 for the dirID.
- long GetDirIDForFolder(short vRefNum, long dirID, const StringPtr folderName);
-
-
- // ForceFinderToUpdateFolder: Given a vRefNum and dirID, force the Finder to flush any cached info
- // for the folder by touching the modification date for this folder.
- OSErr ForceFinderToUpdateFolder(short vRefNum, long dirID);
-
- //
- // Move a file named fileName on the volume vRefNum from the directory sourceDirID to
- // the directory destinationDirID.
- //
- OSErr MoveHFSFile(short vRefNum, long sourceDirID, const StringPtr fileName, long destinationDirID);
-
- //
- // min and max functions
- //
- inline long min(long a, long b) { return (a>b)?b:a; };
- inline long longmin(long a, long b) { return (a>b)?b:a; };
- inline short shortmin(long a, long b) { return (a>b)?b:a; };
-
- inline long max(long a, long b) { return (a>b)?a:b; };
- inline short shortmax(short a, short b) { return (a>b)?a:b; };
- inline long longmax(long a, long b) { return (a>b)?a:b; };
-
- inline between (long x, long low, long high) { return ( (x < low) ? low : ( ( x > high) ? high : x) ); };
- inline shortbetween (short x, short low, short high) { return ( (x < low) ? low : ( ( x > high) ? high : x) ); };
- inline longbetween (long x, long low, long high) { return ( (x < low) ? low : ( ( x > high) ? high : x) ); };
-
-
- // This macro 'references' a variable, so that a '# warning: variable not used' warning is not
- // generated during a compile. This macro should not cause any code to be generated.
- #ifndef __UNUSED__
- #define unused(x) ((void) &x)
- #define __UNUSED__
- #endif
-
- /*-----------------------------------------------------------
- - MatchResString: Determines if a string exists in a
- - STR# list and returns the index
- -
- - theStr: string to search for
- - startIndex: inclusive start of the search
- - endIndex: inclusive end of search
- - resID: STR# res id to look in
- -
- - returns: the index of the string
- ------------------------------------------------------------
- */
-
- extern short MatchResString(const StringPtr theStr, short startIndex, short endIndex, short resID);
- extern pascal void BLJDUc2rString (const char* cStr, short charSet, RString *rStr, unsigned short rStrLength);
- extern ostream& DumpHex (ostream& s, const void *p, unsigned long size);
- extern void GetRezMessage(short rezId, short problemIndex, RString& message);
- extern unsigned long NowDateTime(void); // gets date/time in seconds
-
- //
- // Clear out the structure to all zero's.
- //
- #define CLEARBLOCK(x) memset(&x,0,sizeof(x));
-
- #endif // __UTILITIES__
-